from apps import db
from utils.models import BaseModel


class GoodsCategory(BaseModel, db.Model):
    """商品分类"""
    __tablename__ = "mogu_goods_category"
    id = db.Column(db.Integer, primary_key=True, comment="ID")
    name = db.Column(db.String(64), nullable=True, comment="分类名称")
    goods_list = db.relationship('GoodsSPU', backref='category', lazy='dynamic')

    def __repr__(self):
        return "%s" % (self.name)


class GoodsSPU(BaseModel, db.Model):
    """商品SPU"""
    __tablename__ = "mogu_goods_spu"
    id = db.Column(db.Integer, primary_key=True, comment="ID")
    title = db.Column(db.String(256), nullable=False, comment="商品标题")
    is_recommend = db.Column(db.Boolean, default=False, comment="是否推荐到首页")
    descript = db.Column(db.String(512), nullable=False, comment="商品描述")
    effect = db.Column(db.Text, nullable=False, comment="产品效果")
    image_url = db.Column(db.String(256), default='', comment="封面图片")
    category_id = db.Column(db.Integer, db.ForeignKey("mogu_goods_category.id"), comment="分类ID")
